class dialog{
	constructor(){
		this.node=this.initDialog();
	}
	
	
	addButton(text,fn){
		let button=this.createButton(text);
		button.addEventListener('click',function(e){
			fn(e);
		})
		this.node.dialog_button.appendChild(button);
	}
	
	createDialog(){
		let dialog_node={
			'dialog':this.createNode('DIV','dialog'),
			'dialog_body':this.createNode('DIV','dialog_body'),
			'dialog_head':this.createNode('DIV','dialog_head'),
			'dialog_title':this.createNode('DIV','dialog_title'),
			'title_span':this.createNode('SPAN'),
			'dialog_close':this.createNode("DIV","dialog_close"),
			'close_span':this.createNode('SPAN'),
			'dialog_main_body':this.createNode("DIV","dialog_main_body"),
			'dialog_bottom':this.createNode("DIV","dialog_bottom"),
			'dialog_button':this.createNode("DIV","dialog_button"),
			'dialog_pane':this.createNode("DIV","dialog_pane"),
		}
		return dialog_node;
	}
	
	
	
	createButton(text){
		let button=this.createNode('BUTTON','button','blue','small');
		let textButton=this.createTextNode(text);
		button.appendChild(textButton);
		return button;
	}
	
	createCloseSvg(){
		 const svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
		svgElement.setAttribute("class", "icon");
		svgElement.setAttribute("style", "width: 1em; height: 1em; vertical-align: middle; fill: currentColor; overflow: hidden;");
		svgElement.setAttribute("viewBox", "0 0 1024 1024");
		svgElement.setAttribute("version", "1.1");
		svgElement.setAttribute("xmlns", "http://www.w3.org/2000/svg");
		svgElement.setAttribute("p-id", "3355");
	
		// 创建 <path> 元素，设置路径信息
		const pathElement = document.createElementNS("http://www.w3.org/2000/svg", "path");
		pathElement.setAttribute("d", "M548.992 503.744L885.44 167.328a31.968 31.968 0 1 0-45.248-45.248L503.744 458.496 167.328 122.08a31.968 31.968 0 1 0-45.248 45.248l336.416 336.416L122.08 840.16a31.968 31.968 0 1 0 45.248 45.248l336.416-336.416L840.16 885.44a31.968 31.968 0 1 0 45.248-45.248L548.992 503.744z");
		pathElement.setAttribute("p-id", "3356");
	
		// 将 <path> 元素添加到 <svg> 元素中
		svgElement.appendChild(pathElement);
		return svgElement;
	}
	
	createNode(tagName,className,className2,className3){
		var newNode = document.createElement(tagName);
		if(className){
			newNode.classList.add(className);
		}
		if(className2){
			newNode.classList.add(className2);
		}
		if(className3){
			newNode.classList.add(className3);
		}
		return newNode;
	}
	
	open(){
		this.node.dialog.style.visibility="visible";
	}
	
	close(){
		this.node.dialog.style.visibility="hidden";
	}
	createTextNode(text){
		var newNode=document.createTextNode(text);
		return newNode;
	}
	initDialog(){
		let node=this.createDialog();
		node.dialog.appendChild(node.dialog_body);
		node.dialog.appendChild(node.dialog_pane);
		
		node.dialog_body.appendChild(node.dialog_head);
		node.dialog_body.appendChild(node.dialog_main_body);
		node.dialog_body.appendChild(node.dialog_bottom);
		
		node.dialog_head.appendChild(node.dialog_title);
		node.dialog_head.appendChild(node.dialog_close);
		
		node.dialog_close.appendChild(node.close_span);
		let close_span_svg=this.createCloseSvg();
		node.close_span.appendChild(close_span_svg);
		
		node.dialog_bottom.appendChild(node.dialog_button);
		
		document.body.appendChild(node.dialog);
		//添加关闭
		node.close_span.addEventListener('click',function(e){
			node.dialog.style.visibility="hidden";
		});
		return node;
	}
	
}